<template>
  <div class="wrap-pass">
    <header class="header-back">
      <i class="iconfont fl back" @click="goBack">&#xe624;</i>
      <br style="clear: both;"/>
    </header>
    <div class="center">
      <h3 class="center-h3">使用密码登录</h3>
      <!--form-->
      <div class="form-div">
        <div class="tel-div">
          <input type="number" placeholder="请输入手机号" v-model="userTel"/>
        </div>
        <div class="pass-div">
          <input type="password" placeholder="请输入密码" v-model="userPwd"/>
        </div>
        <div class="btn-div">
          <button @click="doLogin">登录</button>
        </div>
        <!--<div class="forget-div">
          <a href="###">忘记密码?</a>
        </div>-->
      </div>
    </div>
    <div v-show="isOriginHei" class="bottom-div">
      <span>登陆即同意包租公</span>
      <a href="###">用户服务协议</a>
    </div>
  </div>
</template>

<script>
import {loginByPsw, queryAuthenticationInfo} from '../../api/person.js'
export default {
  data () {
    return {
      userTel: '',
      userPwd: '',
      fullHeight: document.documentElement.clientHeight,
      height: document.documentElement.clientHeight,
      isOriginHei: true
    }
  },
  methods: {
    goBack () {
      this.$router.go(-1)
    },
    doLogin () {
      this.loginByPsw()
    },
    async loginByPsw () {
      try {
        let data = await loginByPsw({userPhone: this.userTel, passWord: this.userPwd})
        if (data.data.status === 200) {
          this.$store.state.isLogin = true
          localStorage.isLogin = 'true'
          localStorage.userNum = data.data.userNum
          this.$store.state.userNum = data.data.userNum
          this.$store.state.nickName = data.data.nickName
          this.queryAuthenticationInfo()
          if (this.$route.query.path !== undefined) {
            this.$router.push(this.$route.query.path)
          } else {
            this.$router.push('/index/person')
          }
        } else {
          this.$toast({
            message: '账号或密码错误'
          })
        }
      } catch (err) {
        console.log(err)
      }
    },
    async queryAuthenticationInfo () {
      try {
        let data = await queryAuthenticationInfo({userNum: this.user.userNum})
        if (data.data.status === 200) {
          this.$store.state.isReal = true
        } else {
          this.$store.state.isReal = false
        }
      } catch (err) {
        console.log(err)
      }
    }
  },
  mounted () {
    const that = this
    mui.init({
      keyEventBind: {
        backbutton: true  //关闭back按键监听
      }
    })
    mui.back = function () {
      that.$router.go(-1)
      error
    }
    window.onresize = () => {
      return (() => {
        window.fullHeight = document.documentElement.clientHeight
        that.fullHeight = window.fullHeight
      })()
    }
  },
  watch: {
    fullHeight (val) {
      if (this.height !== val) {
        this.isOriginHei = false
      } else {
        this.isOriginHei = true
      }
    }
  },
  created: function () {
  }
}
</script>

<style scoped>
  input{
    -webkit-touch-callout: none;
    -webkit-user-select: auto;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }
  .header-back{
    line-height: 2rem;
  }
  .back{
    margin-left: .5rem;
    font-size: .8rem;
  }
  .wrap-pass{
    height: 100%;
  }
  .center{
    text-align: center;
    padding: 0 10%;
    margin-top: 2rem;
  }
  .center-h3{
    font-size: 1rem;
    font-weight: 300;
  }
  .form-div{
    margin-top: 2.5rem;
  }
  .form-div input{
    font-size: .7rem;
    padding: .2rem;
  }
  .pass-div{
    margin-top: .5rem;
  }
  .btn-div{
    margin-top: 2rem;
  }
  .btn-div button{
    width: 100%;
    border: none;
    background: #e94c75;
    color: #fff;
    line-height: 1.6rem;
    border-radius: .8rem;
    font-size: .7rem;
    outline: none;
  }
  .forget-div{
    margin-top: .5rem;
    overflow: hidden;
  }
  .forget-div a{
    font-size: .65rem;
    float: right;
    color: #606266;
  }
  .bottom-div{
    font-size: .7rem;
    text-align: center;
    position: absolute;
    bottom: .8rem;
    left: 0;
    right: 0;
  }
  .bottom-div a{
    color: #e94c75;
  }
</style>
